<template>

  <el-col
    v-if="buttonList != null && buttonList.length > 0"
    :span="24"
    class="toolbar"
    style="padding-bottom: 0px;"
  >

    <el-form :inline="true" @submit.native.prevent>
        <el-row style="margin:0px;padding:0px;" >
    <el-form-item label="所属年份" style="margin:0px;padding:0px;" >
          <el-radio-group  size="mini" v-model="currentYear" >
          <el-radio-button  label="0" :key="0">全部</el-radio-button>
              <el-radio-button v-for="item in 5" :label="item+2017" :key="item+2017">{{item+2017}}</el-radio-button>
        </el-radio-group>
        </el-form-item>
        </el-row>
        <el-row style="margin:0px;padding:0px;">
        <el-form-item label="试卷类型" style="margin:0px;padding:0px;" >
          <el-radio-group  size="mini" v-model="selectPaperType" >
              <el-radio-button  label="0" :key="0">全部</el-radio-button>
              <el-radio-button v-for="item in paperEnumList" :label="item.Value" :key="item.Value">{{item.Name}}</el-radio-button>
        </el-radio-group>
        </el-form-item>
        </el-row>
        <el-row style="margin:0px;padding:0px;">
          <el-form-item label="考试类别" style="margin:0px;padding:0px;" >
             <el-radio-group size="mini" v-model="cateogryParam.categoryBase" @change="changeCategory" >
                   <el-radio-button  label="" key=" ">全部</el-radio-button>
                <el-radio-button v-for="item in categoryData" :label="item.ID" :key="item.ID">{{item.Name}}
                </el-radio-button>
             </el-radio-group>
              <p style="margin:0px;padding:0px;">
              <el-radio-group size="mini" v-model="cateogryParam.categoryChild" @change="changeChildCategory">
                <el-radio-button v-for="childItem in childCategory"  :label="childItem.ID" :key="childItem.ID">{{childItem.Name}}
                </el-radio-button>
             </el-radio-group>
             </p>
              <p style="margin:0px;padding:0px;">
              <el-radio-group size="mini" v-model="cateogryParam.categoryNode" >
                <el-radio-button v-for="nodeChildItem in nodeChildCategory" :label="nodeChildItem.ID" :key="nodeChildItem.ID">{{nodeChildItem.Name}}
                </el-radio-button>
             </el-radio-group>
             </p>
          </el-form-item>
        </el-row>
         <el-row style="margin-left:0px;padding:0px;">
           <el-form-item label="试卷名称" >
                     <el-input
          size="mini"
          v-model="searchVal"
          placeholder="请输入内容"
        ></el-input>
             </el-form-item>

      <!-- 这个就是当前页面内，所有的btn列表 -->
      <el-form-item v-for="item in buttonList" v-bind:key="item.id">
        <!-- 这里触发点击事件 -->
        <el-button
          :type="
            item.func &&
            (item.func.toLowerCase().indexOf('handledel') != -1 ||
              item.func.toLowerCase().indexOf('stop') != -1)
              ? 'danger'
              : 'primary'
          "
          size="mini"
          v-if="!item.isHide"
          @click="callFunc(item)"
          >{{ item.name }}</el-button
        >
      </el-form-item>
         </el-row>
    </el-form>
  </el-col>

</template>
<script>
import {
staticPaperEnumList,
getCategoryList
} from "../api/api";
export default {
  name: "PaperToolbar",
  data() {
    return {
         currentYear:0,
         selectPaperType:0,
         paperEnumList:[],
         categoryData:[],
         childCategory:[],
         nodeChildCategory:[],
         searchVal:"",
    };
  },
  props: ["buttonList","cateogryParam"], //接受父组件传值
  methods: {
    callFunc(item) {
      item.paperType=this.selectPaperType;
      item.search = this.searchVal;
     // item.cateogryParam=this.cateogryParam;
      item.currentYear=this.currentYear;
      this.$emit("callFunction", item); //将值传给父组件
    },
    changeCategory(item)
    {
      this.childCategory=[];
      this.nodeChildCategory=[];
     // this.cateogryParam={};
      this.cateogryParam.categoryChild="";
      this.cateogryParam.categoryNode="";
      var _childCategory=[];
      this.categoryData.map(c=>{
          if(c.ID==item){
            _childCategory=c.Children;
          }
      }
      );
      this.childCategory=_childCategory;
      if(this.childCategory.length>0)
      {
        this.cateogryParam.categoryChild=_childCategory[0].ID;
        if(_childCategory[0].Children && _childCategory[0].Children.length>0)
        {
        this.cateogryParam.categoryNode=_childCategory[0].Children[0].ID;
         this.nodeChildCategory=_childCategory[0].Children;
        }
      }
    },
    changeChildCategory(item)
    {
      if(item)
      {
       this.nodeChildCategory=[];
       var _nodeCategory
        this.childCategory.map(c=>{
                   if(c.ID==item){
            _nodeCategory=c.Children;
          } 
        })
      this.nodeChildCategory=_nodeCategory||[];
      if(this.nodeChildCategory.length>0)
      {
        this.cateogryParam.categoryNode=this.nodeChildCategory[0].ID;
  
      }
      }
    },changeYear(item){
      alert(item);
    }
    ,_initCateogry(categoryData)
    {
      this.categoryData=categoryData;
      this.changeCategory(this.cateogryParam.categoryBase);
      if(this.childCategory.length>0)
      {
          this.changeChildCategory(this.cateogryParam.categoryChild);
      
      }
    },
    // initCatalog() {
    //   let param = {};
    //   getCategoryList(param).then((data) => {
    //     if (data.IsSuccess) {
    //       this.categoryData = data.Data.TreeData;
    //       this._initCateogry();
    //     }
    //   });
    // }
  },
   mounted()
   { 
    staticPaperEnumList().then((data)=>{
        this.paperEnumList=data;
    })
   }
};
</script>